package com.braveo.dict;

import android.content.Context;
import android.content.SharedPreferences;

public class BraveConfigManager {
	private static BraveConfigManager manager;
	
	@SuppressWarnings("unused")
	private Context ctx;
	private SharedPreferences settings;
	
	public static final String OPTION_DICT_NAME = "DictName";
	
	private BraveConfigManager(Context ctx) {
		this.ctx = ctx;
		this.settings = ctx.getSharedPreferences("brave-dict", 0);
	}
	
	public static synchronized BraveConfigManager getManager(Context ctx){
		if(manager == null)
			manager = new BraveConfigManager(ctx);
		return manager;
	}
	
	public String getDictName(){
		String dictName = settings.getString(OPTION_DICT_NAME, null);
		if(dictName == null)
			return null;
		
		String dbName = BraveDictDbAdapter.dictShortNameToFullName(dictName);
		if(BraveDictDbAdapter.dictExists(dbName))
			return dictName;
		return null;
	}
	
	public synchronized void setDictName(String dictName){
		SharedPreferences.Editor editor = settings.edit();
		editor.putString(OPTION_DICT_NAME, dictName);
		editor.commit();
	}
	
	

}
